$(function () {
	$('.salesPromotionAdd').on('hidden.bs.modal', function () {
		$('#salesPromotionAdd')[0].reset();
		$('#salesPromotionAdd input:hidden').val('');
		$('#salesPromotionAdd .selectpicker').selectpicker('refresh');
//		$('#matchAdd .sysUser').remove();
		$('#salesPromotionAdd').data('bootstrapValidator').resetForm();
	})
    //日期
    $('#duration').daterangepicker({
		locale : {
			format: 'YYYY-MM-DD',
			separator:' - ',
			applyLabel : '确定',
			cancelLabel : '取消',
			customRangeLabel : '自定义',
			daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
			monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',
				'七月', '八月', '九月', '十月', '十一月', '十二月' ],
			firstDay : 1
		},
		ranges: {
			'今天': [moment().startOf('day'), moment()],
			'昨天': [moment().subtract(1,'days').startOf('day'), moment().subtract(1,'days').endOf('day')],
			'本周': [moment().startOf("week").add(1,'days'),moment().endOf("week").add(1,'days')],
			'上周': [moment().subtract(1,'weeks').startOf("week").add(1,'days'),moment().subtract(1,'weeks').endOf("week").endOf("week").add(1,'days')],
			'本月': [moment().startOf("month"),moment().endOf("month")],
			'上个月': [moment().subtract(1,"month").startOf("month"),moment().subtract(1,"month").endOf("month")],
			'最近7天': [moment().subtract(6,'days'), moment()],
			'最近30天': [moment().subtract(29,'days'), moment()]
		},
		applyClass:'btn-primary',
		alwaysShowCalendars: true,
		autoclose:true
    });
    $('#duration1').daterangepicker({
		locale : {
			format: 'YYYY-MM-DD',
			separator:' - ',
			applyLabel : '确定',
			cancelLabel : '取消',
			customRangeLabel : '自定义',
			daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
			monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',
				'七月', '八月', '九月', '十月', '十一月', '十二月' ],
			firstDay : 1
		},
		ranges: {
			'今天': [moment().startOf('day'), moment()],
			'昨天': [moment().subtract(1,'days').startOf('day'), moment().subtract(1,'days').endOf('day')],
			'本周': [moment().startOf("week").add(1,'days'),moment().endOf("week").add(1,'days')],
			'上周': [moment().subtract(1,'weeks').startOf("week").add(1,'days'),moment().subtract(1,'weeks').endOf("week").endOf("week").add(1,'days')],
			'本月': [moment().startOf("month"),moment().endOf("month")],
			'上个月': [moment().subtract(1,"month").startOf("month"),moment().subtract(1,"month").endOf("month")],
			'最近7天': [moment().subtract(6,'days'), moment()],
			'最近30天': [moment().subtract(29,'days'), moment()]
		},
		applyClass:'btn-primary',
		alwaysShowCalendars: true,
		autoclose:true
    });
    $('#duration2').daterangepicker({
		locale : {
			format: 'YYYY-MM-DD',
			separator:' - ',
			applyLabel : '确定',
			cancelLabel : '取消',
			customRangeLabel : '自定义',
			daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
			monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',
				'七月', '八月', '九月', '十月', '十一月', '十二月' ],
			firstDay : 1
		},
		ranges: {
			'今天': [moment().startOf('day'), moment()],
			'昨天': [moment().subtract(1,'days').startOf('day'), moment().subtract(1,'days').endOf('day')],
			'本周': [moment().startOf("week").add(1,'days'),moment().endOf("week").add(1,'days')],
			'上周': [moment().subtract(1,'weeks').startOf("week").add(1,'days'),moment().subtract(1,'weeks').endOf("week").endOf("week").add(1,'days')],
			'本月': [moment().startOf("month"),moment().endOf("month")],
			'上个月': [moment().subtract(1,"month").startOf("month"),moment().subtract(1,"month").endOf("month")],
			'最近7天': [moment().subtract(6,'days'), moment()],
			'最近30天': [moment().subtract(29,'days'), moment()]
		},
		applyClass:'btn-primary',
		alwaysShowCalendars: true,
		autoclose:true
    });
    $('#duration3').daterangepicker({
		locale : {
			format: 'YYYY-MM-DD',
			separator:' - ',
			applyLabel : '确定',
			cancelLabel : '取消',
			customRangeLabel : '自定义',
			daysOfWeek : [ '日', '一', '二', '三', '四', '五', '六' ],
			monthNames : [ '一月', '二月', '三月', '四月', '五月', '六月',
				'七月', '八月', '九月', '十月', '十一月', '十二月' ],
			firstDay : 1
		},
		ranges: {
			'今天': [moment().startOf('day'), moment()],
			'昨天': [moment().subtract(1,'days').startOf('day'), moment().subtract(1,'days').endOf('day')],
			'本周': [moment().startOf("week").add(1,'days'),moment().endOf("week").add(1,'days')],
			'上周': [moment().subtract(1,'weeks').startOf("week").add(1,'days'),moment().subtract(1,'weeks').endOf("week").endOf("week").add(1,'days')],
			'本月': [moment().startOf("month"),moment().endOf("month")],
			'上个月': [moment().subtract(1,"month").startOf("month"),moment().subtract(1,"month").endOf("month")],
			'最近7天': [moment().subtract(6,'days'), moment()],
			'最近30天': [moment().subtract(29,'days'), moment()]
		},
		applyClass:'btn-primary',
		alwaysShowCalendars: true,
		autoclose:true
    });

    //促销活动类型
    (function () {  
        if ($('.activityType :selected').val() == 1) {
            $('.lowerLimit2').hide();
            $('.discount').show();
        }
        if ($('.activityType :selected').val() == 2) {
            $('.lowerLimit2').hide();
            $('.discount').show();
        }
        if ($('.activityType :selected').val() == 3) {
            $('.lowerLimit2').show();
            $('.discount').hide();
        }
    })();


    //新增促销活动类型切换
       $('.salesPromotionAdd').find('.activityType select').on('change', function () {
            if ($(this).val() == 1) {
                $('.salesPromotionAdd').find('.lowerLimit2').hide();
                $('.salesPromotionAdd').find('.discount').show();
            }
            if ($(this).val() == 2) {
                $('.salesPromotionAdd').find('.lowerLimit2').hide();
                $('.salesPromotionAdd').find('.discount').show();
            }
            if ($(this).val() == 3) {
                $('.salesPromotionAdd').find('.lowerLimit2').show();
                $('.salesPromotionAdd').find('.discount').hide();
            }
            
            var isOverlay = [
                             ["独立", "满额返券", "优惠码"],
                             ["独立", "报名折扣", "优惠码"],
                             ["独立", "报名折扣", "满额返券"]
              ];
            
            var activityType = document.getElementById('activityAdd');
            var overlay = document.getElementById('overlayAdd');
      
                var activityOverlay = isOverlay[activityType.selectedIndex - 1];
                overlay.length = 1;
                for (var i = 0; i < activityOverlay.length; i++) {
                    overlay[i + 1] = new Option(activityOverlay[i], activityOverlay[i]);
                }
            
        })
        //编辑促销活动类型切换
        $('.salesPromotionEdit').find('.activityType select').on('change', function () {
            if ($(this).val() == 1) {
                $('.salesPromotionEdit').find('.lowerLimit2').hide();
                $('.salesPromotionEdit').find('.discount').show();
                $('#overlayEdit option:eq(2)').hide().siblings().show();
            }
            if ($(this).val() == 2) {
                $('.salesPromotionEdit').find('.lowerLimit2').hide();
                $('.salesPromotionEdit').find('.discount').show();
                $('#overlayEdit option:eq(3)').hide().siblings().show();
            }
            if ($(this).val() == 3) {
                $('.salesPromotionEdit').find('.lowerLimit2').show();
                $('.salesPromotionEdit').find('.discount').hide();
                $('#overlayEdit option:eq(1)').hide().siblings().show();
            }
        })

     //初始咨询课程
   	$.ajax({
           url: ctx + '/bizProject/getAllOption',
           type: 'POST',
           dataType: 'json',
           success: function (data) {
       		var zxkc = "";
           	for(var i=0; i<data.list.length; i++){
           		zxkc += "<option value="+data.list[i].projectId+">" + data.list[i].fullName + "</option>";
           	}
           	$('#salesPromotionAdd select[name="project"]').html('<option value="">--请选择--</option>'+zxkc);
           },
           error: function (response) {
           	toastr.error("系统错误");
           }
       });
});
//优惠码查询
var yhmDataTable=function(){
	return{
		init:function(){
			var yhmTable = $('#youHuiCode').dataTable({
				"bPaginate": true,  //是否显示分页
            	"iDisplayLength": 15,
            	"bLengthChange": false,//每页显示的记录数
            	"bFilter": false, //搜索栏
            	"bSort": true, //是否支持排序功能
            	"bInfo": true, //显示表格信息
            	"bAutoWidth": false,  //自适应宽度
            	"bStateSave": true, //保存状态到cookie *************** 很重要 ， 当搜索的时候页面一刷新会导致搜索的消失。使用这个属性就可避免了
            	//"sPaginationType": "", //分页，一共两种样式，full_numbers和two_button(默认)
            	"sAjaxSource" : ctx+'/bizActivityCode/load',
        		"fnServerData": retrieveData,//用于替换默认发到服务端的请求操作  
            	"bServerSide": true,
            	"bDestroy": true,
                "bRetrieve": false,
                "oLanguage" :{
                	"sLengthMenu" : "每页显示 _MENU_ 条记录",
        			"sZeroRecords" : "抱歉， 没有找到",
        			"sInfo" : "从 _START_ 到 _END_ / 共 _TOTAL_ 条数据",
        			"sInfoEmpty" : "找不到相关数据",
        			"sInfoFiltered" : "数据表中共为 _MAX_ 条记录)",
        			"sProcessing": "正在加载中...",
        			"sSearch": "搜索",
        			"oPaginate" : {
        				"sFirst" : "首页",
        				"sPrevious" : "前一页",
        				"sNext" : "后一页",
        				"sLast" : "尾页"
        			},
                },
                "aoColumns" :[ {
	                "mData": "activityCodeId", 'sClass': "text-center", "bSortable": false, "mRender": function (data, type, full) {
		                return '<label  class="labletab" style="padding-top: 0px"> <input name="ajaxcheckbox" type="checkbox" class="checkchild"> <span class="text" ></span> </label>';
		            }
		            },
		            {"mData": "code", 'sClass': "text-center"},
		            {"mData": "beginAndEnd", 'sClass': "text-center"},
		            {"mData": "useStatus", 'sClass': "text-center"},
		            {"mData": "amount", 'sClass': "text-center"},
		            {"mData": "useTime", 'sClass': "text-center"},
		            {"mData": "modifyUserName", 'sClass': "text-center"}],
		            "aoColumnDefs": [{
		   	            sDefaultContent: '',
		   	            aTargets: ['_all']
		   	        }],
		   	        "fnRowCallback":function(nRow,aData,iDisplayIndex){
		   	        	if(aData.useStatus=='0'){
		   	        		$('td:eq(3)',nRow).html('未使用');
		   	        	}else{
		   	        		$('td:eq(3)',nRow).html('已使用');
		   	        	}
		   	        	return nRow;
		   	        },
			});
		}
	}
}();
yhmDataTable.init();
/**
 * 回调函数
 * @param sSource
 * @param aoData
 * @param fnCallback
 * @returns
 */
function retrieveData( sSource, aoData, fnCallback, oSettings ) {
	aoData.push( { "name": "pageNum", "value": (Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength )+1) });
    aoData.push( { "name": "pageSize", "value": oSettings._iDisplayLength });  
    
    var searchVal = $('#status').val();
    
    if(searchVal && searchVal.length != 0){
    	aoData.push({ "name": "searchVal", "value": searchVal});
    }
    
    $.ajax( {  
        "url": sSource,  
        "data": aoData,  
        "cache": false,  
        "dataType": 'json', 
        "type": "POST", 
        "success" :function(response) {
        	fnCallback(response.returnObject);
        }  
    } );  
}
//新增优惠码 promoCodeAdd
$('#promoCodeAdd').bootstrapValidator({
	 message: 'This value is not valid',
     fields: {//表单验证
    	 amount: {
             validators: {
                 notEmpty: {
                     message: '金额不能为空'
                 }
             }
         },
         num: {
             validators: {
                 notEmpty: {
                     message: '数量不能为空'
                 }
             }
         },
         duration: {
             validators: {
                 notEmpty: {
                     message: '起始时间不能为空'
                 }
             }
         },
     },
     submitHandler: function (validator, form, submitButton) {
    	 var youhuimaNum = $('.youhuima .num').val();
    	 var duration = $('.youhuima .duration').val();
		 var amount = $('.youhuima .amount').val();
		 var beginTime =duration.split(" - ")[0];
		 var endTime =duration.split(" - ")[1];
    	 for(i=0;i<youhuimaNum;i++){
    		 $.ajax({
                 url: ctx + '/bizActivityCode/addNewRecord',
                 type: 'POST',
                 data:{"amount":amount,
                       "beginTime":beginTime,
                       "endTime":endTime
                 },
                 dataType: 'json',
                 success: function (data) {
                     if (data.status == "success"){
                    	 $('.promoCodeAdd').modal('hide');
                    	 yhmDataTable.init();
                     }
                     else
                     	toastr.error(data.msg);
                 },
                 error: function (response) {
                 	toastr.error("系统错误");
                 }
             });
    	 }
         return false;
     }
});
//查寻促销活动
var cxDataTable=function(){
	return{
		init:function(){
			var cxTable = $('#cuXiao').dataTable({
				"bPaginate": true,  //是否显示分页
            	"iDisplayLength": 5,
            	"bLengthChange": false,//每页显示的记录数
            	"bFilter": false, //搜索栏
            	"bSort": true, //是否支持排序功能
            	"bInfo": true, //显示表格信息
            	"bAutoWidth": false,  //自适应宽度
            	"bStateSave": true, //保存状态到cookie *************** 很重要 ， 当搜索的时候页面一刷新会导致搜索的消失。使用这个属性就可避免了
            	//"sPaginationType": "", //分页，一共两种样式，full_numbers和two_button(默认)
            	"sAjaxSource" : ctx+'/bizActivity/load',
        		"fnServerData": retrieveDataCx,//用于替换默认发到服务端的请求操作  
            	"bServerSide": true,
            	"bDestroy": true,
                "bRetrieve": false,
                "oLanguage" :{
                	"sLengthMenu" : "每页显示 _MENU_ 条记录",
        			"sZeroRecords" : "抱歉， 没有找到",
        			"sInfo" : "从 _START_ 到 _END_ / 共 _TOTAL_ 条数据",
        			"sInfoEmpty" : "找不到相关数据",
        			"sInfoFiltered" : "数据表中共为 _MAX_ 条记录)",
        			"sProcessing": "正在加载中...",
        			"sSearch": "搜索",
        			"oPaginate" : {
        				"sFirst" : "首页",
        				"sPrevious" : "前一页",
        				"sNext" : "后一页",
        				"sLast" : "尾页"
        			},
                },
                "aoColumns" :[ {
	                "mData": "activityId", 'sClass': "text-center", "bSortable": false, "mRender": function (data, type, full) {
		                return '<label  class="labletab" style="padding-top: 0px"> <input name="ajaxcheckbox" type="checkbox" class="checkchild"> <span class="text" ></span> </label>';
		            }
		            },
		            {"mData": "title", 'sClass': "text-center"},//标题
		            {"mData": "bizProject.fullName", 'sClass': "text-center"},//项目名称（后期关联）
		            {"mData": "beginTime", 'sClass': "text-center"},//开始日期
		            {"mData": "endTime", 'sClass': "text-center"},//结束日期
		            {"mData": "discount", 'sClass': "text-center"},//折扣
		            {"mData": "type", 'sClass': "text-center"},//类型
		            {"mData": "enable", 'sClass': "text-center","bSortable": false,"mRender":function(data, type, full ){
							if(data==0){
								return '<span id="span'+full["activityId"]+'" onclick="chooseStudent(\''+full["activityId"]+'\')" class="btn btn-xs btn-nouse"><i class="fa fa-ban"></i> 禁用</span>';
							}else{
								return '<span id="span'+full["activityId"]+'" onclick="chooseStudent(\''+full["activityId"]+'\')" class="btn btn-xs btn-use"><i class="fa fa-check-circle-o"></i> 启用</span>';
							}
						}
					},//状态
		            {
		                "mData": "activityId",
		                'sClass': "text-center",
		                "bSortable": false,
		                "mRender": function (data, type, full ) {
    			                    var u = '<a onclick="edit(\''+full["title"]
    			    				+'\',\''+full["project"]
    			    				+'\',\''+full["type"]
    			    				+'\',\''+full["isMulti"]
    			    				+'\',\''+full["discount"]
    			    				+'\',\''+full["limit1"]
    			    				+'\',\''+full["limit2"]
    			    				+'\',\''+full["beginTime"]
    			                    +'\',\''+full["endTime"]
    			                    +'\',\''+full["enable"]
    			                    +'\',\''+full["description"]
    			    				+'\')" class="btn btn-warning btn-xs edit" data-toggle="modal" data-target=".salesPromotionView" data-backdrop="static"><i class="fa fa-folder-open-o"></i> 查看</a>';
    			                    var d = '<a onclick="editupdt(\''+full["title"]
    			                    +'\',\''+full["activityId"]
    			    				+'\',\''+full["project"]
    			    				+'\',\''+full["type"]
    			    				+'\',\''+full["isMulti"]
    			    				+'\',\''+full["discount"]
    			    				+'\',\''+full["limit1"]
    			    				+'\',\''+full["limit2"]
    			    				+'\',\''+full["beginTime"]
    			                    +'\',\''+full["endTime"]
    			                    +'\',\''+full["enable"]
    			                    +'\',\''+full["description"]
    			    				+'\')" class="btn btn-info btn-xs edit" data-toggle="modal" data-target=".salesPromotionEdit" data-backdrop="static" '+(full.enable == 0 ? "disabled" : "")+'><i class="fa fa-edit"></i> 编辑</a>';
    			                    return u + d;
		                }
		            }//操作
		            ],
		            "aoColumnDefs": [{
		   	            sDefaultContent: '',
		   	            aTargets: ['_all']
		   	        }],
		   	     "fnRowCallback":function(nRow,aData,iDisplayIndex){
			   	    	 if(aData.discount==""){
			   	    		$('td:eq(5)',nRow).html('0.00');
			   	    	 }
		   	        	if(aData.type=='1'){
		   	        		$('td:eq(6)',nRow).html('报名折扣');
		   	        	}else if(aData.type=='2'){
		   	        		$('td:eq(6)',nRow).html('满额返券');
		   	        	}else if(aData.type=='3'){
		   	        		$('td:eq(6)',nRow).html('优惠码');
		   	        	}
		   	        	return nRow;
		   	        },
			});
		}
	}
}();
//编辑取值
function editupdt(title,activityId,project,type,isMulti,discount,limit1,limit2,beginTime,endTime,enable,description){
	var beginAndEnd = beginTime+" - "+endTime;
	var discountUpdt= "";
	if(discount==null||discount==""){
		discountUpdt="0.00";
	}else{
		discountUpdt = discount;
	}
	var lowerLimit2 = "";
	if(limit2=="null"||limit2==""){
		lowerLimit2="0.00";
	}else{
		lowerLimit2=limit2;
	}
	$('#titleUpdt').val(title);
	$('#activityId').val(activityId);
	var projectId = project;
	$.ajax({
        url: ctx + '/bizProject/getAllOption',
        type: 'POST',
        dataType: 'json',
        success: function (data) {
    		var opt = "";
        	for(var i=0; i<data.list.length; i++){
        		opt += "<option value="+data.list[i].projectId+">" + data.list[i].fullName + "</option>";
        	}
        	$('#salesPromotionEdit select[name="project"]').html(opt);
        	$('#salesPromotionEdit select[name="project"]').val(project);
        },
        error: function (response) {
        	toastr.error("系统错误");
        }
    });
//	$('#projectUpdt').val(project);
	$('#activityEdit').val(type);
	$('#overlayEdit').val(isMulti);
	$('#discountUpdt').val(discountUpdt);
	$('#lowerLimit1').val(limit1);
	$('#lowerLimit2').val(lowerLimit2);
	$('#duration2').val(beginAndEnd);
	$('#enableUpdt').val(enable);
	$('#descriptionUpdt').val(description);
	
	if(type == '1'){
		$('#overlayEdit option:eq(2)').hide().siblings().show();
	}
	if(type == '2'){
		$('#overlayEdit option:eq(3)').hide().siblings().show();
	}
	if(type == '3'){
		$('#overlayEdit option:eq(1)').hide().siblings().show();
	}
	
}
//编辑插入
$('#salesPromotionEdit').bootstrapValidator({
	submitHandler: function (validator, form, submitButton) {
		var duration2 = $('#salesPromotionEdit input[name="duration2"]').val();
		
		var beginTime =duration2.split(" - ")[0];
		var endTime =duration2.split(" - ")[1];
		var activityId = $('#salesPromotionEdit input[name="activityId"]').val();
		var title = $('#salesPromotionEdit input[name="title"]').val();
		var project = $('#salesPromotionEdit select[name="project"]').val();
		var type = $('#salesPromotionEdit select[name="activityType"]').val();
		var isMulti = $('#salesPromotionEdit select[name="overlay"]').val();
		var discount = $('#salesPromotionEdit input[name="discount"]').val();
		var limit1 = $('#salesPromotionEdit input[name="lowerLimit1"]').val();
		var limit2 = $('#salesPromotionEdit input[name="lowerLimit2"]').val();
		var enable = $('#salesPromotionEdit select[name="enable"]').val();
		var description = $('#salesPromotionEdit textarea[name="description"]').val();
		$.ajax({
			url : ctx + '/bizActivity/updateRecord',
			data : {activityId:activityId,title:title,project:project,type:type,
				isMulti:isMulti,discount:discount,limit1:limit1,limit2:limit2,
				enable:enable,description:description,beginTime:beginTime,endTime:endTime},
			dataType : 'json',
			type : 'POST',
			success : function(data){
				$('.salesPromotionEdit').modal('hide');
//				$('#salesPromotionEdit button[type="submit"]').removeAttr('disabled');
				cxDataTable.init();
			},
			error : function(){
				toastr.error("没有修改内容提交！");
			}
		});
	}
});
//查看
function edit(title,project,type,isMulti,discount,limit1,limit2,beginTime,endTime,enable,description){
	var beginTime = beginTime;
	var endTime = endTime;
	var beginAndEnd = beginTime+" - "+endTime
	var typeView = "";
		if(type==1){
			typeView ="报名折扣";
		}else if(type==2){
			typeView ="满额返券";
		}else{
			typeView ="优惠码";
		}
	var isMultiView ="";
	if(isMulti==0){
		isMultiView="独立";
	}else if(isMulti==1){
		isMultiView="优惠码";
	}else if(isMulti==2){
		isMultiView="报名折扣";
	}else if(isMulti==3){
		isMultiView="满额返券";
	}
	var enableView = "";
	if(enable==0){
		enableView="无效"
	}else if(enable==1){
		enableView="有效"
	}
	var discountView= "";
	if(discount==null||discount==""){
		discountView="0.00";
	}else{
		discountView = discount;
	}
	var limit2View = "";
	if(limit2=="null"||limit2==""){
		limit2View="0.00";
	}else{
		limit2View=limit2;
	}
	$('#titleView').val(title);
	var projectId = project;
	$.ajax({
        url: ctx + '/bizProject/getAllOption',
        type: 'POST',
        data:{projectId:projectId},
        dataType: 'json',
        success: function (data) {
        	$('#projectView').val(data.list[0].fullName);
        },
        error: function (response) {
        	toastr.error("系统错误");
        }
    });
	$('#typeView').val(typeView);
	$('#isMultiView').val(isMultiView);
	$('#discountView').val(discountView);
	$('#limit1View').val(limit1);
	$('#limit2View').val(limit2View);
	$('#beginAndEnd').val(beginAndEnd);
	$('#enableView').val(enableView);
	$('#descriptionView').val(description);
}
cxDataTable.init();
function retrieveDataCx( sSource, aoData, fnCallback, oSettings ) {
	
	var beganAndEnd = $("#duration1").val();
    if(beganAndEnd && beganAndEnd.length != 0){
    	var minDate = trim(beganAndEnd.split(" - ")[0]);
        var maxDate = trim(beganAndEnd.split(" - ")[1]);
        aoData.push({ "name": "beginTime", "value": minDate });
        aoData.push({ "name": "endTime", "value": maxDate });
    }
	
	aoData.push( { "name": "pageNum", "value": (Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength )+1) });
    aoData.push( { "name": "pageSize", "value": oSettings._iDisplayLength });
	aoData.push( { "name": "enable", "value": $("#enable").val()});
    var searchVal = $('#searchVal').val();
    if(searchVal && searchVal.length != 0){
    	aoData.push({ "name": "searchVal", "value": searchVal});
    }
    $.ajax( {  
        "url": sSource,  
        "data": aoData,  
        "cache": false,  
        "dataType": 'json', 
        "type": "POST", 
        "success" :function(response) {
        	fnCallback(response.returnObject);
        }  
    } );  

}
//修改状态
function chooseStudent(val,flag){
	var attr = $("#span"+val).attr("class");
	if(attr == "btn btn-xs btn-nouse"){
		flag = 1;
	}else{
		flag = 0;
	}
	$.ajax({
        url: ctx + '/bizActivity/updateRecord',
        type: 'POST',
        data: {
        	activityId:val,
        	enable:flag
        },
        dataType: 'json',
        success: function (data) {
        	/*if(data.status == 'success' && flag == 1){
        		$("#span"+val).removeClass("btn-nouse").addClass("btn-use");
        		$("#span"+val).html('<i class="fa fa-check-circle-o"></i> 启用');
        	}
        	if(data.status == 'success' && flag == 0){
        		$("#span"+val).removeClass("btn-use").addClass("btn-nouse");
        		$("#span"+val).html('<i class="fa fa-ban"></i> 禁用');
        	}*/
        	cxDataTable.init();
        }
	});
}

//新增促销活动
$('#salesPromotionAdd').bootstrapValidator({
    submitHandler: function (validator, form, submitButton) {
    	var duration3 = $('#salesPromotionAdd input[name="duration3"]').val();
    	var beginTime =duration3.split(" - ")[0];
		var endTime =duration3.split(" - ")[1];
		var title = $('#salesPromotionAdd input[name="title"]').val();
		var project = $('#salesPromotionAdd select[name="project"]').val();
		var type = $('#salesPromotionAdd select[name="type"]').val();
		if(type == 0){
			toastr.error("类型不能为空，请选择！");
			return;
		}
		var ifMulti = $('#salesPromotionAdd select[name="isMulti"]').val();
		var isMulti = "";
		if(ifMulti=="独立"){
			var isMulti=0;
		}else if(ifMulti=="优惠码"){
			var isMulti=1;
		}else if(ifMulti=="报名折扣"){
			var isMulti=2;
		}else if(ifMulti=="满额返券"){
			var isMulti=3;
		}else{
			toastr.error("请选择可叠加优惠！");
			return;
		}
		var discount = $('#salesPromotionAdd input[name="discountAdd"]').val();
		var limit1 = $('#salesPromotionAdd input[name="limit1"]').val();
		var limit2 = $('#salesPromotionAdd input[name="limit2"]').val();
		var enable = $('#salesPromotionAdd select[name="enable"]').val();
		var description = $('#salesPromotionAdd textarea[name="description"]').val();
        $.ajax({
            url: ctx + '/bizActivity/addNewRecord',
            type: 'POST',
            data: {title:title,project:project,type:type,isMulti:isMulti,
            	discount:discount,limit1:limit1,limit2:limit2,
            	enable:enable,description:description,beginTime:beginTime,
            	endTime:endTime},
            dataType: 'json',
            success: function (data) {
                if (data.status == "success"){
                	$('.salesPromotionAdd').modal('hide');
//                	$('#salesPromotionAdd button[type="submit"]').removeAttr('disabled');
                	cxDataTable.init();
                }
                else{
                	toastr.error(data.msg);
                }
            },
            error: function (response) {
            	toastr.error("系统错误");
            }
        });
    }
});
//回车搜索
function search(){
	if(event.keyCode==13){
		cxDataTable.init();
	}
}